package com.dmall.algorithm.chapter03;

import java.util.Arrays;

public class Leetcode26 {

    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int index = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[index] != nums[i]) {
                index++;
                nums[index] = nums[i];
            }
        }
        return index + 1;
    }

    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        Leetcode26 leetcode26 = new Leetcode26();
        System.out.println(leetcode26.removeDuplicates(nums));
        System.out.println();
        Arrays.stream(nums).forEach(System.out::println);
    }
}
